Skip to content

fix(complexity): point the nesting suggestion at the deepest block - #874

Merged
DaisukeYoda merged 1 commit into
ludo-technologies:mainfrom
dodoshell:fix/deepest-nesting-line
Nov 2, 2026
Merged

DaisukeYoda merged 1 commit into
ludo-technologies:mainfrom
dodoshell:fix/deepest-nesting-line

Conversation

@dodoshell

Copy link
Copy Markdown
Contributor

Summary

For functions nested deeper than 4 levels, the suggestion step "Identify the deepest nested block at line N" always printed the function's def line. CalculateMaxNestingDepth already finds the right line, but CalculateComplexityWithConfig only kept MaxDepth. This carries DeepestNestingLine through analyzer.ComplexityResult into domain.ComplexityMetrics and uses it in the suggestion.

Type of Change

  • Bug fix (non-breaking change)
  • New feature (non-breaking change)
  • Breaking change
  • Documentation update
  • Performance improvement
  • Refactoring

Related Issues

Fixes #870

Changes

  • internal/analyzer/complexity.go: keep DeepestNestingLine from the nesting result in ComplexityResult
  • domain/complexity.go: add DeepestNestingLine to ComplexityMetrics, exposed as deepest_nesting_line, and list it in website/docs/output/schemas.md
  • service/complexity_service.go: map it into the domain metrics
  • domain/suggestion.go: use it in the nesting step, falling back to StartLine when it is 0
  • Tests: the suggestion step uses the deepest line, falls back to the start line without one, and the service reports line 9 for a shortened version of the repro in the issue

Testing

  • make test passes locally (the new and touched tests pass; see below for the rest)
  • make lint passes locally (go vet is clean; gofmt is clean on the changed files, see below)
  • Added tests for new functionality (if applicable)

I ran these on Windows, where some existing tests fail on main as well (path separators in the module rollups, OS error text in file_reader_test.go), and golangci-lint reports gofmt on three files this PR doesn't touch because of the CRLF checkout. Both are the same with and without this change. The new tests pass, and fail without the fix.

Verified Against a Real Project

  • Repository: ppizarror/pygame-menu at 5acb8ff1 (the project from the issue)
  • Command: pyscn analyze --json --no-open --select complexity pygame_menu
  • Observed before/after: the five nesting suggestions moved from the def lines to the deepest blocks, e.g. Menu.update 2683 → 3015 and RangeSlider.update 1164 → 1322 (both checked in the source). Scores and other findings are unchanged.

Documentation

  • Updated godoc comments
  • Updated README or other docs (if needed)

Additional Context

@DaisukeYoda DaisukeYoda left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@DaisukeYoda
DaisukeYoda merged commit 5a0459f into ludo-technologies:main Nov 2, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG][auto] complexity-deepest-nesting-line-not-surfaced: 'deepest nested block at line N' suggestion prints the def line

2 participants